<?php 
//获取传递的mid电影是否属于付费电影
header("content-type:text/html;charset=utf8");
$uid = isset($_GET['uid'])?$_GET['uid']:'';
$mid = isset($_GET['mid'])?$_GET['mid']:'';
$return = array();
if ($mid) {
	$pdo = new PDO('mysql:host=123.57.16.97;dbname=project','root','zqVnUy6cxsQXbpEZ');
	$pdo->exec("set names utf8");
	$movieInfo = getPayMovieInfo($pdo,$mid);
	if ($movieInfo) {
		if ($uid) {
			$payMovieInfo = getPayMovieStatus($pdo,$uid,$mid);
			if ($payMovieInfo) {
				$return['code'] = 10000;
				$return['data']	= 'This film is a paid information. But this user has already paid';
			}else{
				$return['code'] = 10003;
				$return['data']	= $movieInfo;
			}
		}else{
			$return['code'] = 10003;
			$return['data']	= $movieInfo;
		}
	}else{
		$return['code'] = 10002;
		$return['data'] = 'This film does not belong to pay information';
	}
}else{
	//参数缺少，请确认参数信息
	$return['code'] = 10001;
	$return['data'] = 'Lack of necessary parameters';
}

echo json_encode($return);

//获取此ID的电影是否是属于付费信息
function getPayMovieInfo($pdo,$mid){
	$sql = "SELECT price FROM `movie` WHERE mid = '".$mid."'";
	$movieInfo = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
	return $movieInfo;
}

//获取此用户是否对此条信息进行了付费
function getPayMovieStatus($pdo,$uid,$mid){
	$sql = "SELECT `oid` FROM `order` WHERE uid = '$uid' AND mid = '$mid' AND `status` = 1";
	$payMovieInfo = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
	return $payMovieInfo;
}
 ?>